
package uia.alumni.data;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;


/**
 * Entity for a Group of users.
 * @author Ohm.
 * @version 1.0 - deployeble.
 */
@Entity
@Table(name="ALUMNIGROUP")
@NamedQueries({
    @NamedQuery(
        name="group.findAll",
        query="SELECT g FROM Group g ORDER BY g.gName"
    )
})
public class Group {

    // Private fields.
    @Id() @GeneratedValue()
    @Column(name="GROUPID", nullable=false)
    private long gid;

    @Column(name="NAME", unique=true, nullable=false)
    private String gName;

    @Column(name="DESCRIPTION", nullable=false)
    private String gDesc;

    @Column(name="SUPERGROUP")
    private long superGid;

    // Relation to another group that owns it.
    // Many groups can own one group.
    // One group can be owned by One group.
    @ManyToOne
    private Group superGroup;

    @OneToMany
    private List<Group> underGroups;
    

    @Column(name="TAGS", nullable=false)
    // Make tags a own object?
    private ArrayList<String> tags;

    // Foreign key from user.
    @Column(name="GROUPOWNER", nullable=false, updatable=false, insertable=false)
    private long gOwnerId;

    // Relation to the User that is the owner of the group
    // One owner can own Many groups
    // One group can have one owner.
    @ManyToOne(optional=false)
        @JoinColumn(name="GROUPOWNER", referencedColumnName="USERID")
    private User gOwner;

    private List<User> groupMembers;

    // Constructors.
    public Group(){
        // Default do nothing constructor.
    }

    public Group(String gName, String gDesc, long superGid, long gOwnerId){

        this.gName = gName;

        this.gDesc = gDesc;

        this.superGid = superGid;

        this.gOwnerId = gOwnerId;

        tags = new ArrayList<String>();

        underGroups = new ArrayList<Group>();

        groupMembers = new ArrayList<User>();

    }

    // Methods.
        // Need methods for filling out the lists/sets
        // Deleting objects.
        // and so on.......

    // Getters and Setters.
    public long getGid() {
        return gid;
    }

    public String getgName() {
        return gName;
    }

    public void setgName(String gName) {
        this.gName = gName;
    }

    public String getgDesc() {
        return gDesc;
    }

    public void setgDesc(String gDesc) {
        this.gDesc = gDesc;
    }

    public long getSuperGid() {
        return superGid;
    }

    public Group getSuperGroup() {
        return superGroup;
    }

    public List<Group> getUnderGroups() {
        return underGroups;
    }

    public void setUnderGroups(List<Group> underGroups) {
        this.underGroups = underGroups;
    }

    public ArrayList<String> getTags() {
        return tags;
    }

    public void setTags(ArrayList<String> tags) {
        this.tags = tags;
    }

    public long getgOwnerId() {
        return gOwnerId;
    }

    public User getgOwner() {
        return gOwner;
    }

    public void setgOwner(User gOwner) {
        this.gOwner = gOwner;
    }

    public List<User> getGroupMembers() {
        return groupMembers;
    }

    public void setGroupMembers(List<User> groupMembers) {
        this.groupMembers = groupMembers;
    }

}